package com.ky.service.impl;

import com.ky.Common.Result;
import com.ky.entity.Staff;
import com.ky.mapper.StaffMapper;
import com.ky.service.StaffService;
import com.ky.untils.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class StaffServiceImpl implements StaffService {
    @Autowired
    private StaffMapper staffMapper;
    @Override
    public List<Staff> findall() {
        List<Staff> findall = staffMapper.findall ();
        return findall;
    }

    @Override
    public Result login(String username, String password) {
        Staff staff = staffMapper.login (username, password);
        if(staff == null){
            return Result.fail ("用户账号不存在或密码错误");
        }
        Map<String, Object> claims = new HashMap<> ();
        claims.put ("id",staff.getId ());
        claims.put ("username",username);
        String token = JwtUtil.genToken (claims);
        return Result.ok (token);

    }
}
